# 短信异步任务
from celery_tasks.main import celery_app
from .SMSYuntongxun.SMSMessgeCode import send_message
from celery_tasks.common import sms_constants
import logging
logger = logging.getLogger(__name__)
@celery_app.task(name='test')
def test_code():
    print("我正在测试异步任务...")
    logger = logging.getLogger('celery')
    logger.info('This is a test log message')
@celery_app.task(name='send_sms_message')
def send_sms_code(mobile,sms_code):
    print("异步任务开始")
    logger.info(f"开始发送  {mobile} 短信验证码 {sms_code}")
    try:
        response = send_message(mobile, (sms_code, sms_constants.SMS_CODE_REDIS_EXPIRES // 60))
        logger.info(f"短信验证码已成功发送到 {mobile}, response: {response}")
    except Exception as e:
        logger.error(f"短信验证发送失败 {mobile}, error: {str(e)}")
        raise e